﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;

/// <summary>
/// Summary description for FormulaDAO
/// </summary>
public class FormulaDAO : dataAccess
{
    public FormulaDAO()
    {

    }
    public DataSet getAllFormulars()
    {
        string sql = "select td1.FormulaName, td1.Code, td1.Description, td1.CreatedDate, td1.ModifiedDate,td3.AnimalName as Animal from (select * from Formula) td1, Animal td3 where td1.AnimalID = td3.AnimalID ";
        return getData(sql);
    }
    public DataSet getUserFormulars(String userID)
    {
        string sql = "select td1.FormulaName, td1.Code, td1.Description, td1.CreatedDate, td1.ModifiedDate,td3.AnimalName as Animal from (select * from Formula) td1, Animal td3 where td1.AnimalID = td3.AnimalID and UserID ='" + userID + "'";
        return getData(sql);
    }
    public DataSet getcbb()
    {
        string sql = "SELECT AnimalName AS 'Animal',AnimalID FROM Animal";
        return getData(sql);
    }
    public void addNew(Formula formular)
    {

        String sql = String.Format("insert into Formula (FormulaID,UserID,FormulaName,Code,[Description],CreatedDate,ModifiedDate,AnimalID)values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}')", formular.Id, "CD774C95-F613-4C98-934D-00EF7C1AECE7", formular.Name, formular.Code, formular.Description, formular.CreatedDate, formular.Modifieddate, formular.AnimalID);
        executeQuery(sql);
    }
    public void update(Formula formular)
    {
        string sql = "Update Formula set FormulaName='" + formular.Name + "', Code='" + formular.Code + "',Description='" + formular.Description + "'";
        executeQuery(sql);
    }
}